package gui.utils;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.font.FontRenderContext;
import java.awt.image.BufferedImage;
import javax.swing.BorderFactory;
import javax.swing.border.TitledBorder;

/*Author: John Archer, Contact: john.archer.jpa@gmail.com*/
public class Borders {
    public static int SEQCHARHEIGHT = 0;
    public static int SEQ_CHAR_WIDTH = 0;
    public static int SEQFONTSIZE = 14;

    public static int STANDARD_TITLED_BORDER = 0;
    public static int LIGHT_TITLED_BORDER = 1;
    public static TitledBorder getTitledBorder(int which, String title){
        if(which==STANDARD_TITLED_BORDER){
            TitledBorder b = BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(new Color(178, 178,178), new Color(178, 178,178)), title);
            b.setTitleFont(getFont(GUIFONT));
            return b;
        }
        else if(which==LIGHT_TITLED_BORDER){
            TitledBorder b = BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(new Color(210, 210,210), new Color(210, 210, 210)), title);
            b.setTitleFont(getFont(GUIFONT));
            return b;
        }
        return null;
    }
    public static int GUIFONT = 0;
    public static int GUIFONTBLD = 1;
    public static int SEQFONT = 2;
    public static int SEQFONTBLD = 3;
    public static int GENOWINFONT = 4;

    public static Font getFont(int which){
        if(which==GUIFONT){return new Font("Tahoma", Font.PLAIN, 12);}
        else if(which==GUIFONTBLD){return new Font("Tahoma", Font.BOLD, 12);}
        else if(which==SEQFONT){return new Font("Courier", Font.PLAIN, SEQFONTSIZE);}
        else if(which==SEQFONTBLD){return new Font("Courier", Font.BOLD, SEQFONTSIZE);}
        else if(which==GENOWINFONT){return new Font("Courier", Font.BOLD, 8);}
        return null;
    }

    public static void setCharHeightAndWidth(){
        BufferedImage bufferedImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
        Graphics g = bufferedImage.createGraphics();
        Graphics2D g2 = (Graphics2D)g;
        g2.setFont(getFont(SEQFONT));
        FontRenderContext fg = g2.getFontRenderContext();
        SEQ_CHAR_WIDTH = (int)g2.getFont().getStringBounds("I", fg).getWidth();
        SEQCHARHEIGHT = (int)g2.getFont().getStringBounds("I", fg).getHeight();
    }
}